package com.bosssoft.user.permission.center.serve.api;



import com.bosssoft.user.permission.center.serve.pojo.dto.*;
import com.bosssoft.user.permission.center.serve.pojo.query.RoleQuery;
import com.bosssoft.user.permission.center.serve.pojo.query.RoleUserQuery;
import com.bosssoft.user.permission.center.serve.pojo.vo.RoleCompanyVO;
import com.bosssoft.user.permission.center.serve.pojo.vo.RoleUserVO;
import com.bosssoft.user.permission.center.serve.pojo.vo.RoleVO;

import common.data.commonresponse.CommonPage;
import common.data.commonresponse.CommonResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 描述: 实现角色模块的功能
 * 作者: lljm
 * 日期: 2024/6/11
 */

//@CrossOrigin
@Api(tags = "角色管理 ", value = "/api/v1/permission/role")
@RequestMapping("/api/v1/permission")
@Validated
public interface RoleApi {

   /* ------------------------------角色相关------------------------------*/


    @ApiOperation( value = "查询角色列表",notes="查询角色，也可按照名称查询。以当前登陆用户的公司ids为基础")
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "请求执行没有成功但是发生异常")
    }
    )
    @GetMapping("/role")
    CommonResponse<CommonPage<RoleVO>> search(@NotNull RoleQuery roleQuery);




    @ApiOperation( value = "增加角色")
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "请求执行没有成功但是发生异常")
    }
    )
    @PostMapping("/role")
    CommonResponse<Boolean> add(@NotNull @Valid @RequestBody RoleDTO roleDTO);


    @ApiOperation( value = "更新角色信息")
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "请求执行没有成功但是发生异常")
    }
    )
    @PutMapping("/role")
    CommonResponse<Boolean> update(@NotNull @Valid @RequestBody RoleDTO roleDTO);


    @ApiOperation( value = "批量或单个删除角色")
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "请求执行没有成功但是发生异常")
    }
    )
    @DeleteMapping("/role")
    CommonResponse<Boolean> remove(@RequestBody @NotNull List<Long> ids);


    @ApiOperation(value = "检查角色编号是否重复")
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "请求执行没有成功但是发生异常")
    }
    )
    @GetMapping("/role/check/code")
    CommonResponse<String> checkRoleCode(@RequestParam(value = "code", required = true) String code,@RequestParam (value = "roleId", required = false) Long roleId);






    /* ------------------------------角色 资源  相关------------------------------*/


    @ApiOperation( value = "查看角色资源")
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "请求执行没有成功但是发生异常")
    }
    )
    @GetMapping("/role/resource")
    CommonResponse<Object> showRoleResource(RoleResourceCheckDTO roleResourceCheckDTO);




    @ApiOperation(value = "检查当前角色是否有关联资源")
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "请求执行没有成功但是发生异常")
    }
    )
    @GetMapping("/role/resource/check")
    CommonResponse<String> checkRoleIfHavingResource(@RequestParam(value = "roleId") Long roleId);




    @ApiOperation( value = "分配资源给角色")
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "请求执行没有成功但是发生异常")
    }
    )
    @PostMapping("/role/resource")
    CommonResponse<Boolean> allocateResource(@RequestBody RoleResourceDTO roleResourceDTO);


    /* ------------------------------角色 资源  公司   相关------------------------------*/

    //仅包含一个post方法 功能： 为多角色 分配公司和资源  实现事物

    @ApiOperation( value = "将角色分配给公司 同时给角色分配资源")
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "请求执行没有成功但是发生异常")
    }
    )
    @PostMapping("/role/resourceandcompany")
    CommonResponse<Boolean> allocateResourceAndCompany(@RequestBody RoleResourceAndCompanyDTO roleResourceAndCompanyDTO);






    /* ------------------------------角色 公司  相关------------------------------*/




    @ApiOperation( value = "将角色分配给公司")
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "请求执行没有成功但是发生异常")
    }
    )
    @PostMapping("/role/company")
    CommonResponse<Boolean> allocateCompany(@RequestBody RoleCompanyDTO roleCompanyDTO);



    @ApiOperation( value = "查看当前角色分配的公司列表")
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "请求执行没有成功但是发生异常")
    }
    )
    @GetMapping("/role/company")
    CommonResponse<List<RoleCompanyVO>> checkRoleCompany(@RequestParam("roleIds") List<Long> roleIds);






    /* ------------------------------角色 用户  相关------------------------------*/


    @ApiOperation( value = "查看角色已分配的用户列表")
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "请求执行没有成功但是发生异常")
    }
    )
    @GetMapping("/role/user")
    CommonResponse<CommonPage<RoleUserVO>> checkRoleUser(RoleUserQuery roleUserQuery);




    @ApiOperation( value = "分配角色给用户")
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "请求执行没有成功但是发生异常")
    }
    )
    @PostMapping("/role/user")
    CommonResponse<Boolean> allocateUser(@RequestBody RoleUserDTO roleUserDTO);



}
